// ---------------------------------------------------------------------
//
// -- 复活面板
// -- author £
//
// ---------------------------------------------------------------------

const CommonUtil = require('CommonUtil'),
    superClass = require('AlertWindow');

cc.Class({
    extends: superClass,

    properties: {
        numScore: require('BaseNum'),
        btnRevive: cc.Node,
        btnReviveOld: cc.Node,
        sharedView: cc.Sprite,
        numBonus: require('BaseNum'),
        numCd: require('BaseNum'),
        btnSkip: cc.Node,
        toggleAuto: cc.Toggle,
        adLayer: cc.Node,
        noAdLayer: cc.Node,
    },

    ctor: function () {
        this._update = false;
        this.tex = new cc.Texture2D();
        this._uItr = 0;
        this._updateCount = 0;
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let UIManager = require('UIManager'),
            adEnable = require('Platform').videoAdEnable();

        CommonUtil.mysuper(superClass, this, 'onLoad');
        this.node.height = UIManager.getRealH();
        this.sharedView.node.y = - UIManager.getRootY();
        this.sharedView.node.height = UIManager.getRealH();
        // this.numBonus.updateNum('a' + require('GameConfig').reviveScore() + 'b');
        this.adLayer.active = adEnable;
        this.noAdLayer.active = !adEnable;
    },

    start () {
    },

    show: function (score) {
        let autoRevive = require('CommonInfo').getAutoRevive();

        if (autoRevive === undefined || autoRevive === null)
            autoRevive = true;

        CommonUtil.mysuper(superClass, this, 'show');
        this.toggleAuto.isChecked = autoRevive;
        this.sharedView.spriteFrame = null;
        // this.numScore.updateNum(score);
        this._updateCount = 0;
        this._uItr = 0;
        this._update = true;
    },

    hide: function (data) {
        CommonUtil.mysuper(superClass, this, 'hide');
        this._update = false;
    },

    updateCD: function (time) {
        this.numCd.updateNum(time);
    },

    getData: function () {
        return this.toggleAuto.isChecked;
    },

    clear: function () {
        this.sharedView.spriteFrame = null;
    },

    update (dt) {
        if (!require('AppInfo').wx) return;
        if (!sharedCanvas) return;
        if (!this._update) return;

        ++ this._updateCount;

        if (this._updateCount === 30) {
            this._update = false;
        }

        if (this._uItr !== 3) {
            ++this._uItr;
        } else {
            this._uItr = 0;
            require('Platform').updateSub(this.tex, this.sharedView);
        }
    },
});
